/*------------------------------------------------------------------------------
*** PURPOSE: 	The following do-file generates Table 1 in the Appendix of the
				paper "Respondent biases in household surveys" by Andrew Dillon 
				and Edouard Romeo Mensah. 

*** NOTE:		Relevant globals are defined in the do-file titles "master.do"
				contained in the folder "02_do" in the replication package.
------------------------------------------------------------------------------*/


	* Appendix Table 1. Balancing tests on HH Head's demographics, housing, and 
	* asset characteristics.
		
	la var headgender 		"Female HH head"
	la var headage 			"Age of HH head"
	la var headmigrant 		"HH head migrant"
	la var headfinfeduc 	"Formal or informal educ"	
	la var headfeduc 		"Formal educ"
	la var headfeduclvl_1 	"No educ"
	la var headfeduclvl_2 	"Primary educ"
	la var headfeduclvl_3 	"Jun sec educ"
	la var headfeduclvl_4 	"Sen sec educ"
	la var headfeduclvl_5 	"Univ educ"
	la var nhouse 			"# buildings in dwelling"
	la var nrooms 			"# rooms in dwelling"
	la var asset_index_d 	"HH asset index"
	la var quart_1 			"1st quartile"
	la var quart_2 			"2nd quartile"
	la var quart_3 			"3rd quartile"
	la var quart_4 			"4th quartile"
	la var quint_1 			"1st quintile"
	la var quint_2 			"2nd quintile"
	la var quint_3 			"3rd quintile"
	la var quint_4 			"4th quintile"
	la var quint_5 			"5th quintile"
	la var headrel_1 		"Muslim rel" 
	la var headrel_2 		"Catholic rel" 
	la var headrel_3 		"Protestant rel" 
	la var headrel_4 		"Traditional rel" 
	la var headrel_5 		"Other rel"
	
	#d ;

	global bvars "headgender headage headmigrant headfinfeduc headfeduc 
		headfeduclvl_1 headfeduclvl_2 headfeduclvl_3 headfeduclvl_4 headfeduclvl_5
		headmarried hhsize nmalechild0_5 nfemalechild0_5 nmalechild6_17
		nfemalechild6_17 nmaleadult18_65 nfemaleadult18_65
		nmalesenior66 nfemalesenior66
		hhproptyowner nhouse nrooms asset_index_d
		quart_1 quart_2 quart_3 quart_4" ;	
	global nv = wordcount("$bvars") ;
	disp "$nv" ;
	
	#d cr

	eststo clear
	foreach i of varlist $bvars {
		reg `i' i.treat1_hhead i.treat2_rproxy, vce(cluster village)
		qui sum `i' if e(sample) & control==1
		local ctrlmean=r(mean)
		local ctrlsd=r(sd)
		testparm i.treat1_hhead i.treat2_rproxy
		local pvalue_all=r(p)
		lincom 1.treat1_hhead - 1.treat2_rproxy
		local Treat1_2_coef=r(estimate)
		local Treat1_2_t=r(estimate)/r(se)
		local Treat1_2_p= tprob(r(df),abs(`Treat1_2_t'))	
		eststo `i'_A, addscalars(pvalue_all `pvalue_all' Controlmean `ctrlmean' Controlsd `ctrlsd' ///
		Treat1_2_coef `Treat1_2_coef' Treat1_2_t `Treat1_2_t' pvalue_b1_b2 `Treat1_2_p')
	}	

	
		
	esttab *_A using "04_output\Appendix Tables 1A 1B 1C. BalancingTest-Covariates.csv", se ///
			scalars("pvalue_b1_b2 p-value: test of T1=T2" "pvalue_all p-value: joint test of T1 and T2" N "Controlmean Mean of dependent variable in control households" "Controlsd S.D. of depedent variable in control households") sfmt(3 3 0 3 3) ///
			title("Appendix Tables 1A 1B 1C: Balancing Test on Covariates") ///
			mtitles("Female HH head" "Age of HH head" "HH head migrant" "Received formal or informal education" "Received formal education" "Level of formal education: none" "Level of formal education: primary" "Level of formal education: junior secondary" "Level of formal education: senior secondary" "Level of formal education: university" "HH head married" "HH size" "Number of male children: 0-5" "Number of female children: 0-5" "Number of male children: 6-17" "Number of female children: 6-17" "Number of male adults: 18-65" "Number of female adults 18-65" "Number of male seniors: 66+" "Number of female seniors: 66+" "HH head owns the HH dwelling" "Number of buildings in the dwelling" "Number of rooms in the dwelling" "HH asset index" "HH asset index quartile: 1" "HH asset index quartile: 2" "HH asset index quartile: 3" "HH asset index quartile: 4") ///
			nonotes addnotes("All standard errors are clustered at the village level. *** p<0.01; ** p<0.05; * p<0.1.") star(* 0.1 ** 0.05 *** 0.01) ///
			coeflabels(1.treat1_hhead "T1: HH Head" 1.treat2_rproxy "T2: Random Proxy") drop(0.treat1_hhead 0.treat2_rproxy _cons) ///
			b(3) se(3) noobs width(25) replace
			
			estimates clear	
		
		
		